# -*- coding: utf-8 -*-
import sys
from PySide2 import QtCore,QtGui,QtWidgets

class LoginWidget(QtWidgets.QWidget):
    def __init__(self,parent=None):
        QtWidgets.QWidget.__init__(self,parent)
        #用户标签
        userLabel=QtWidgets.QLabel(self.tr("用户："))
        #用户输入框
        self.userEdit=QtWidgets.QLineEdit()
        #密码票签
        passwdLabel=QtWidgets.QLabel(self.tr("密码："))
        #密码输入框
        self.passwdEdit=QtWidgets.QLineEdit()
        #密码输入框 内容显示
        self.passwdEdit.setEchoMode(QtWidgets.QLineEdit.Password)

        self.submitButton=QtWidgets.QPushButton(self.tr("登录"))
        self.cancelButton=QtWidgets.QPushButton(self.tr("取消"))


        gridlayout=QtWidgets.QGridLayout()
        gridlayout.addWidget(userLabel,0,0,1,1)
        gridlayout.addWidget(self.userEdit,0,1,1,3)
        gridlayout.addWidget(passwdLabel,1,0,1,1)
        gridlayout.addWidget(self.passwdEdit,1,1,1,3)

        hbboxlayout=QtWidgets.QHBoxLayout()
        hbboxlayout.setSpacing(60)
        hbboxlayout.addWidget(self.submitButton)
        hbboxlayout.addWidget(self.cancelButton)

        layout = QtWidgets.QVBoxLayout()
        layout.setMargin(40)
        layout.addLayout(gridlayout)
        layout.addStretch(40)
        layout.addLayout(hbboxlayout)

        self.connect(self.cancelButton,QtCore.SIGNAL("clicked()"),
                     QtWidgets.qApp,QtCore.SLOT("quit()"))

        self.connect(self.submitButton,QtCore.SIGNAL("clicked()"),
                     self.loginClicked)

        self.setLayout(layout)
        self.setWindowTitle(self.tr("登录"))
        self.resize(300,200)
        self.moveToCenterScreen()

    def loginClicked(self):
        if self.userEdit.text() !='arc' and self.passwdEdit.text() !='arc':
            QtWidgets.QMessageBox.warning(self,self.tr("警告"),self.tr("用户名或密码不对"),QtWidgets.QMessageBox.Yes);
            self.userEdit.setFocus()
        else:
            QtCore.QCoreApplication.instance().quit()
        pass

    def moveToCenterScreen(self):
        screen = QtWidgets.QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width()-size.width())/2,(screen.height()-size.height())/2)

if __name__=="__main__":
    app=QtWidgets.QApplication(sys.argv)
    widget=LoginWidget()
    widget.show()
    sys.exit(app.exec_())